package com.bridgeintelligent.tag.webserver.dim.mgmt.service.catalog;

import cn.hutool.json.JSONUtil;
import com.bridgeintelligent.tag.mapper.CatalogMapper;
import com.bridgeintelligent.tag.mapper.DimMapper;
import com.bridgeintelligent.tag.mapper.IndexDimMapper;
import com.bridgeintelligent.tag.user.mgmt.pojo.User;
import com.bridgeintelligent.tag.utils.SecurityHelper;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.BaseCode;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimCatalog;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimData;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.DimRep;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.enums.CatalogEnum;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.indexdim.DimInfoModel;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.indexdim.IndexDimModel;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.vo.DimCatalogVO;
import com.bridgeintelligent.tag.webserver.dim.mgmt.service.es.IEsInfoService;
import com.bridgeintelligent.tag.webserver.dim.mgmt.service.indexdim.IIndexDimService;
import com.bridgeintelligent.tag.webserver.security.TagSecurityHelper;
import com.wayneleo.quickstart.framework.IDGenerator;
import lombok.AllArgsConstructor;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

import static com.bridgeintelligent.tag.constants.TagConstants.PRIVATE_CATALOGID;
import static com.bridgeintelligent.tag.constants.TagConstants.SENSITIVE_CATALOG;

/**
 * Created by JackCheung on 2019/9/9 10:12 PM.1
 */
@Service
@AllArgsConstructor
public class CatalogService implements ICatalogService {

    private CatalogMapper catalogMapper;
    private DimMapper dimMapper;
    private IEsInfoService esInfoService;
    private static final String FIRST_INDEX = "1";
    private IndexDimMapper indexDimMapper;

    private IIndexDimService indexDimService;

    @Override
    public DimRep findCatalogList() {
        List<DimCatalog> result = catalogMapper.findCatalogList();
        Map<String, List<DimCatalog>> dimListMap = result.stream()
                                                         .collect(Collectors.groupingBy(DimCatalog::getParentId));
        List<DimCatalog> list = new ArrayList<>(result.size());
        Map<String, DimCatalog> dimMap = result.stream()
                                               .collect(Collectors.toMap(DimCatalog::getId, dimCatalog -> dimCatalog));
        List<DimCatalog> parentList = dimListMap.get("-");
        parentList.forEach(dimCatalog -> list.add(findVO(dimListMap, dimMap, dimCatalog.getId())));
        test(parentList, "", "");
        parentList.sort(Comparator.comparing(DimCatalog::getNumber));
        return new DimRep<>(parentList, BaseCode.SUCCESS);
    }

    @Override
    public DimRep findShowCatalogList(boolean sensitive,String indexId) {
        List<DimCatalog> result;
        //如果没有传索引默认走当前索引即查询所有目录
        if (!StringUtils.equals("1",indexId)){
            List<String> catalogs = indexDimService.findCatalogIdByDims(indexId);
            result = catalogMapper.findCatalogByIds(catalogs);
        }else{
            result = catalogMapper.findCatalogList();
        }

        //此处代码说明：业务将一级目录:敏感目录 调整为了二级目录,同时去除了私有标签目录
        if (!sensitive){
            result = result.stream().filter(e-> !e.getName().equals(SENSITIVE_CATALOG)).collect(Collectors.toList());
        }

        Map<String, List<DimCatalog>> dimListMap = result.stream()
                .collect(Collectors.groupingBy(DimCatalog::getParentId));
        Map<String, DimCatalog> dimMap = result.stream()
                .collect(Collectors.toMap(DimCatalog::getId, dimCatalog -> dimCatalog));
        List<DimCatalog> parentList = dimListMap.get("-");
        test(parentList, "", "");
        buildTree(dimListMap, dimMap, parentList);

        List<DimCatalog> defaultList = parentList.stream().filter(e -> e.getName().equals("默认目录")).collect(Collectors.toList());
        parentList = parentList.stream().filter(e-> !e.getName().equals("默认目录")).sorted(Comparator.comparing(DimCatalog::getNumber)).collect(Collectors.toList());

        Integer max = parentList.get(parentList.size() - 1).getNumber();
        DimCatalog shareDims = new DimCatalog().setNumber(max+1).setLevel(1).setIdPath(",")
                .setNamePath(",").setParentId("-").setName(CatalogEnum.SHARED_TAG.getCatalogName()).setId(CatalogEnum.SHARED_TAG.getCatalogId())
                .setChildren(new ArrayList<>());

        //此处代码说明，将一级目录：默认目录放在最后，共享目录放在最前
        List<DimCatalog> realList = new ArrayList<>();
        realList.add(shareDims);
        realList.addAll(parentList);
        if (!CollectionUtils.isEmpty(defaultList)){
            realList.addAll(defaultList);
        }
        return new DimRep<>(realList, BaseCode.SUCCESS);
    }

    private void buildTree(Map<String, List<DimCatalog>> dimListMap, Map<String, DimCatalog> dimMap, List<DimCatalog> parentList) {
        DimCatalog privateCatalog = null;
        int offset = 0;
        for(int i = 0;i<parentList.size();i++){
            DimCatalog dimCatalog = parentList.get(i);
            if(StringUtils.equals(PRIVATE_CATALOGID, dimCatalog.getName())){
                offset = i;
                privateCatalog = findVO(dimListMap, dimMap, dimCatalog.getId());
            }else{
                findVO(dimListMap, dimMap, dimCatalog.getId());
            }
        }
        if(privateCatalog!=null){
            parentList.remove(offset);
            parentList.add(privateCatalog);
        }
    }

    private void buildTree2(Map<String, List<DimCatalogVO>> dimListMap, Map<String, DimCatalogVO> dimMap,List<DimCatalogVO> parentList) {
        DimCatalogVO privateCatalog = null;
        int offset = 0;
        for(int i = 0;i<parentList.size();i++){
            DimCatalogVO dimCatalog = parentList.get(i);
            if(StringUtils.equals(PRIVATE_CATALOGID, dimCatalog.getName())){
                offset = i;
                privateCatalog = buildVO(dimListMap, dimMap, dimCatalog.getId());
            }else{
                buildVO(dimListMap, dimMap, dimCatalog.getId());
            }
        }
        if(privateCatalog!=null){
            parentList.remove(offset);
            parentList.add(privateCatalog);
        }
    }

    @Override
    public DimRep findDimTree(boolean sensitive) {
        // 需要查一下es跑批时间
        String dataTime = esInfoService.dataTime();
        String current = DateFormatUtils.format(new Date(), DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.getPattern());
        List<DimCatalogVO> result = catalogMapper.findCatalogs();

        //此处代码说明：敏感目录被业务将一级目录调整为了二级目录
        if (!sensitive){
            result = result.stream().filter(e-> !e.getName().equals(SENSITIVE_CATALOG)).collect(Collectors.toList());
        }

        User user = TagSecurityHelper.currentUser();
        result.forEach(catalog -> catalog.getChildren()
                                         .addAll(dimMapper.findDimVOsByCatalogId(current, catalog.getId(),
                                                 user.getUserId(),dataTime)));
        Map<String, List<DimCatalogVO>> dimListMap = result.stream()
                                                           .collect(Collectors.groupingBy(DimCatalogVO::getParentId));
        Map<String, DimCatalogVO> dimMap = result.stream()
                                                 .collect(Collectors.toMap(DimCatalogVO::getId, dimCatalog -> dimCatalog));
        List<DimCatalogVO> parentList = dimListMap.get("-");
        parentList.sort(Comparator.comparing(DimCatalogVO::getNumber));
        buildTree2(dimListMap, dimMap, parentList);
        setShareTags(current, parentList, dataTime);
        return new DimRep<>(parentList, BaseCode.SUCCESS);
    }

    @Override
    public DimRep findIndexDimTree(boolean sensitive,String indexId) {
        // 需要查一下es跑批时间
        String dataTime = esInfoService.indexDataTime(indexId);
        String current = DateFormatUtils.format(new Date(), DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.getPattern());
        List<DimCatalogVO> result;
        if (!StringUtils.equals("1",indexId)){
            List<String> catalogs = indexDimService.findCatalogIdByDims(indexId);
            result = catalogMapper.findCatalogsNew(catalogs);
        }else{
            result = catalogMapper.findCatalogs();
        }

        //此处代码说明：现在业务将一级目录:敏感目录 调整为了二级目录,同时去掉私有标签目录
        if (!sensitive){
            result = result.stream().filter(e-> !e.getName().equals(SENSITIVE_CATALOG)).collect(Collectors.toList());
        }

        //根据索引ID获取对应标签配置信息
        List<String> indexDimList = new ArrayList<>();
        if (!FIRST_INDEX.equals(indexId)){
            IndexDimModel indexDim = indexDimMapper.findIndexDimById(Integer.valueOf(indexId));
            if (indexDim != null && !StringUtils.isEmpty(indexDim.getIndexDim())){
                List<DimInfoModel> infoModels = JSONUtil.toList(indexDim.getIndexDim(), DimInfoModel.class);
                List<String> dimIds = infoModels.stream().map(e -> e.getDimId()).collect(Collectors.toList());
                indexDimList.addAll(dimIds);
            }
        }
        List<String> indexDimList1 = indexDimList;
        User user = TagSecurityHelper.currentUser();
        result.forEach(catalog -> catalog.getChildren()
                .addAll(dimMapper.findIndexDimVOsByCatalogId(current, catalog.getId(),
                        user.getUserId(),dataTime,indexDimList1)));
        Map<String, List<DimCatalogVO>> dimListMap = result.stream()
                .collect(Collectors.groupingBy(DimCatalogVO::getParentId));
        Map<String, DimCatalogVO> dimMap = result.stream()
                .collect(Collectors.toMap(DimCatalogVO::getId, dimCatalog -> dimCatalog));

        List<DimCatalogVO> parentList = dimListMap.get("-");
        parentList.sort(Comparator.comparing(DimCatalogVO::getNumber));
        buildTree2(dimListMap, dimMap, parentList);

        List<DimCatalogVO> defaultList = parentList.stream().filter(e -> e.getName().equals("默认目录")).collect(Collectors.toList());
        parentList = parentList.stream().filter(e-> !e.getName().equals("默认目录")).sorted(Comparator.comparing(DimCatalogVO::getNumber)).collect(Collectors.toList());

        Integer max = parentList.get(parentList.size() - 1).getNumber();
        List<Object> dims = new ArrayList<>(16);
        dims.addAll(dimMapper.findSharedDims(current, user.getUserId(), dataTime));
        // 共享标签
        DimCatalogVO shareDims = new DimCatalogVO().setNumber(max+1).setLevel(1).setIdPath(",")
                .setNamePath(",").setParentId("-").setName(CatalogEnum.SHARED_TAG.getCatalogName()).setId(CatalogEnum.SHARED_TAG.getCatalogId())
                .setChildren(dims);
        List<DimCatalogVO> realList = new ArrayList<>();
        realList.add(shareDims);
        realList.addAll(parentList);
        if (!CollectionUtils.isEmpty(defaultList)){
            realList.addAll(defaultList);
        }
        return new DimRep<>(realList, BaseCode.SUCCESS);
    }

    private void setShareTags(String current, List<DimCatalogVO> parentList, String dataTime) {
        Integer max = parentList.get(parentList.size() - 1).getNumber();
        User user = TagSecurityHelper.currentUser();
        List<Object> dims = new ArrayList<>(16);
        dims.addAll(dimMapper.findSharedDims(current, user.getUserId(), dataTime));
        // 共享标签
        DimCatalogVO shareDims = new DimCatalogVO().setNumber(max+1).setLevel(1).setIdPath(",")
                .setNamePath(",").setParentId("-").setName(CatalogEnum.SHARED_TAG.getCatalogName()).setId(CatalogEnum.SHARED_TAG.getCatalogId())
                .setChildren(dims);


        parentList.add(shareDims);
    }

    private void setIndexShareTags(String current, List<DimCatalogVO> parentList, String dataTime,List<String> indexDimList) {
        Integer max = parentList.get(parentList.size() - 1).getNumber();
        User user = TagSecurityHelper.currentUser();
        List<Object> dims = new ArrayList<>(16);
        dims.addAll(dimMapper.findIndexSharedDims(current, user.getUserId(), dataTime,indexDimList));
        // 共享标签
        DimCatalogVO shareDims = new DimCatalogVO().setNumber(max+1).setLevel(1).setIdPath(",")
                .setNamePath(",").setParentId("-").setName(CatalogEnum.SHARED_TAG.getCatalogName()).setId(CatalogEnum.SHARED_TAG.getCatalogId())
                .setChildren(dims);
        parentList.add(shareDims);
    }

    private void test(List<DimCatalog> parentList, String name, String id) {
        parentList.forEach(dimCatalog -> {
            dimCatalog.setNamePath(name + "," + dimCatalog.getName() + ",");
            dimCatalog.setIdPath(id + "," + dimCatalog.getId() + ",");
            dimCatalog.getChildren()
                      .forEach(dimCatalog1 -> {
                          dimCatalog1.setNamePath(dimCatalog.getNamePath() + dimCatalog1.getName());
                          dimCatalog1.setIdPath(dimCatalog.getIdPath() + dimCatalog1.getId());
                          test(dimCatalog1.getChildren(), dimCatalog1.getNamePath(), dimCatalog1.getIdPath());
                      });
        });
    }

    private DimCatalogVO buildVO(Map<String, List<DimCatalogVO>> dimListMap, Map<String, DimCatalogVO> dimMap, String id) {
        DimCatalogVO dimCatalog = dimMap.get(id);
        List<DimCatalogVO> list = dimListMap.get(dimCatalog.getId());
        if (CollectionUtils.isEmpty(list)) {
            return dimCatalog;
        }
        list.sort(Comparator.comparing(DimCatalogVO::getNumber));
        list.forEach(dimCatalog1 -> {
            DimCatalogVO catalogVOChirld = buildVO(dimListMap, dimMap, dimCatalog1.getId());
            dimCatalog.getChildren()
                      .add(catalogVOChirld);
        });
        return dimCatalog;
    }

    private DimCatalog findVO(Map<String, List<DimCatalog>> dimListMap, Map<String, DimCatalog> dimMap, String id) {
        DimCatalog dimCatalog = dimMap.get(id);
        List<DimCatalog> list = dimListMap.get(dimCatalog.getId());
        if (null != list) {
            list.sort(Comparator.comparing(DimCatalog::getNumber));
            list.forEach(dimCatalog1 -> {
                DimCatalog catalogVOChirld = findVO(dimListMap, dimMap, dimCatalog1.getId());
                dimCatalog.getChildren()
                          .add(catalogVOChirld);
            });
        } else {
            return dimCatalog;
        }
        return dimCatalog;
    }

    @Override
    public DimRep del(String id) {
        List<DimCatalog> list = catalogMapper.findNext(id);
        if (list.isEmpty()) {
            catalogMapper.del(id);
            return new DimRep<>("删除成功", 0);
        } else {
            return new DimRep<>("删除失败，此目录有下级目录！", 999);
        }
    }

    @Override
    public DimRep put(String parentId, String name, Integer number) {
        int result = catalogMapper.findCatalogNameIsExits(name, parentId);
        if (result > 0) {
            return new DimRep(BaseCode.FAIL, "同级目录下目录名重复！");
        }
        String id = IDGenerator.gen();
        int level;
        if (PARENT_ID.equals(parentId)) {
            level = 1;
        } else {
            level = catalogMapper.findParent(parentId) + 1;
        }
        if (level > 3) {
            return new DimRep(BaseCode.FAIL, "只能创建3级目录！");
        }
        catalogMapper.add(id, name, parentId, findMax(parentId), level);
        return new DimRep<>("新增成功", 0);
    }

    private int findMax(String parentId) {
        Integer max = catalogMapper.findMaxNumber(parentId);
        return max == null ? 0 : max + 1;
    }

    @Override
    public synchronized DimRep update(String id, String parentId, String name, Integer number) {
        DimCatalog dimCatalog = catalogMapper.findById(id);
        updateHandler(dimCatalog, id, parentId, name, number);
        return new DimRep<>("修改成功", 0);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateHandler(DimCatalog dimCatalogOld, String id, String parentId, String name, Integer number) {
        boolean isUp = false, isChangePosition = true;
        DimCatalog dimCatalog = new DimCatalog();
        dimCatalog.setId(id)
                  .setParentId(parentId)
                  .setName(name)
                  .setNumber(number);
        if (null != number && number.equals(dimCatalogOld.getNumber())) {
            isChangePosition = false;
        }
        if (isChangePosition) {
            DimCatalog neighbor = catalogMapper.findByNumber(dimCatalogOld.getParentId(), number);
            if (neighbor != null) {
                neighbor.setNumber(dimCatalogOld.getNumber());
                catalogMapper.update(neighbor);
            }
        }
        catalogMapper.update(dimCatalog);
    }

    @Override
    public DimRep dimList(String id) {
        String dataTime = esInfoService.dataTime();
        String current = DateFormatUtils.format(new Date(), DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.getPattern());
        User user = TagSecurityHelper.currentUser();
        if(id != null&& StringUtils.equals(CatalogEnum.SHARED_TAG.getCatalogId(),id)){
            return new DimRep<>(dimMapper.findSharedDims(current, user.getUserId(),dataTime), BaseCode.SUCCESS);
        }
        List<DimData> allDimData = new ArrayList<>();
        allDimData.addAll(dimMapper.findDimVOsByCatalogId(current, id, user.getUserId(), dataTime));
        List<DimCatalog> catalogs = catalogMapper.findNext(id);
        List<String> nextCataIds = catalogs.stream()
                                           .map(DimCatalog::getId)
                                           .collect(Collectors.toList());
        nextCataIds.forEach(cid -> {
            allDimData.addAll(dimMapper.findDimVOsByCatalogId(current, cid, user.getUserId(), dataTime));
        });
        return new DimRep<>(allDimData, BaseCode.SUCCESS);
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("hehe");
        list.add("haha");
        list.add("heihei");
        String json = JSONUtil.toJsonStr(list);
        System.out.println(json);
        List<String> list1 = JSONUtil.toList(json, String.class);
        list1.forEach(e->{
            System.out.println(e);
        });

    }

    @Override
    public DimRep indexDimList(String id,String indexId) {
        String dataTime = esInfoService.indexDataTime(indexId);
        String current = DateFormatUtils.format(new Date(), DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.getPattern());
        User user = TagSecurityHelper.currentUser();
        //根据索引ID获取对应标签配置信息
        List<String> indexDimList = new ArrayList<>();
        if (!FIRST_INDEX.equals(indexId)){
            IndexDimModel indexDim = indexDimMapper.findIndexDimById(Integer.valueOf(indexId));
            if (indexDim != null && !StringUtils.isEmpty(indexDim.getIndexDim())){
                List<DimInfoModel> infoModels = JSONUtil.toList(indexDim.getIndexDim(), DimInfoModel.class);
                List<String> dimIds = infoModels.stream().map(e -> e.getDimId()).collect(Collectors.toList());
                indexDimList.addAll(dimIds);
            }
        }
        if(id != null&& StringUtils.equals(CatalogEnum.SHARED_TAG.getCatalogId(),id)){
            return new DimRep<>(dimMapper.findIndexSharedDims(current, user.getUserId(),dataTime,indexDimList), BaseCode.SUCCESS);
        }
        List<DimData> allDimData = new ArrayList<>();
        allDimData.addAll(dimMapper.findIndexDimVOsByCatalogId(current, id, user.getUserId(), dataTime,indexDimList));
        List<DimCatalog> catalogs = catalogMapper.findNext(id);
        List<String> nextCataIds = catalogs.stream()
                .map(DimCatalog::getId)
                .collect(Collectors.toList());
        //Variable used in lambda expression should be final or effectively final
        List<String> indexDimList1 = indexDimList;
        nextCataIds.forEach(cid -> {
            allDimData.addAll(dimMapper.findIndexDimVOsByCatalogId(current, cid, user.getUserId(), dataTime,indexDimList1));
        });
        return new DimRep<>(allDimData, BaseCode.SUCCESS);
    }

    @Override
    public DimRep dimAllList(String id) {
        String current = DateFormatUtils.format(new Date(), DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.getPattern());
        User user = TagSecurityHelper.currentUser();
        List<DimData> allDimData = new ArrayList<>(dimMapper.findDimVOs(current, id, user.getUserId()));
        List<DimCatalog> catalogs = catalogMapper.findNext(id);
        List<String> nextCataIds = catalogs.stream()
                .map(DimCatalog::getId)
                .collect(Collectors.toList());
        nextCataIds.forEach(cid -> {
            allDimData.addAll(dimMapper.findDimVOs(current, cid, user.getUserId()));
        });
        return new DimRep<>(allDimData, BaseCode.SUCCESS);
    }

    @Override
    public DimRep listInMine() {
        User user = SecurityHelper.currentUser();
        String userId = user.getUserId();
        return new DimRep<>(catalogMapper.listInMine(userId), BaseCode.SUCCESS);
    }

    @Override
    public DimRep dimListInMine(String id) {
        User user = SecurityHelper.currentUser();
        String userId = user.getUserId();
        return new DimRep<>(dimMapper.dimListInMine(id, userId), BaseCode.SUCCESS);
    }

    @Override
    public DimRep indexDimListInMine(String id,String indexId) {
        User user = SecurityHelper.currentUser();
        String userId = user.getUserId();
        //根据索引ID获取对应标签配置信息
        List<String> indexDimList = new ArrayList<>();
        if (!FIRST_INDEX.equals(indexId)){
            IndexDimModel indexDim = indexDimMapper.findIndexDimById(Integer.valueOf(indexId));
            if (indexDim != null && !StringUtils.isEmpty(indexDim.getIndexDim())){
                List<DimInfoModel> infoModels = JSONUtil.toList(indexDim.getIndexDim(), DimInfoModel.class);
                List<String> dimIds = infoModels.stream().map(e -> e.getDimId()).collect(Collectors.toList());
                indexDimList.addAll(dimIds);
            }
        }
        return new DimRep<>(dimMapper.indexDimListInMine(id, userId,indexDimList), BaseCode.SUCCESS);
    }

    /**
     * 根据父id查找其下的标签和目录
     *
     * @return
     */
    @Override
    public DimRep findDimAndCatalog(String parentId) {
        Map<String, List> map = new HashMap<>();
        //当前目录下的标签
        List<DimData> dimList = dimMapper.findDimsByCatalogId(parentId);
        map.put("dimList", dimList);
        //当前目录的子目录
        List<DimCatalog> catalogList = catalogMapper.findNext(parentId);
        map.put("catalogList", catalogList);
        return new DimRep<>(map, BaseCode.SUCCESS);
    }

    @Override
    public String findCatalogByName(String catalogName) {
        Map<String,String> map = new HashMap();
        map.put("name",catalogName);
        return catalogMapper.findCatalogByName(map);
    }

    @Override
    public DimRep indexCombiantion(String indexId) {
        String dataTime = esInfoService.indexDataTime(indexId);
        String current = DateFormatUtils.format(new Date(), DateFormatUtils.ISO_8601_EXTENDED_DATE_FORMAT.getPattern());
        User user = TagSecurityHelper.currentUser();
        //根据索引ID获取对应标签配置信息
        List<String> indexDimList = new ArrayList<>();
        if (!FIRST_INDEX.equals(indexId)){
            IndexDimModel indexDim = indexDimMapper.findIndexDimById(Integer.valueOf(indexId));
            if (indexDim != null && !StringUtils.isEmpty(indexDim.getIndexDim())){
                List<DimInfoModel> infoModels = JSONUtil.toList(indexDim.getIndexDim(), DimInfoModel.class);
                List<String> dimIds = infoModels.stream().map(e -> e.getDimId()).collect(Collectors.toList());
                indexDimList.addAll(dimIds);
            }
        }
        List<DimData> indexCombination = dimMapper.findIndexCombination(current, user.getUserId(), dataTime, indexDimList);
        return new DimRep<>(indexCombination, BaseCode.SUCCESS);
    }
}
